package com.zoe.app.mapper;

import com.zoe.app.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Zoe.Zhang
 * @date 2021/10/13
 * @description
 */
public interface UserMapper {
    @Select("select * from user where id = #{id} ")
    List<User> getUserById(Long id);

    @Results({
        @Result(property = "birthday", column = "ubirthday")
    })
    @Select("select id,name , birthday as ubirthday from user  ")
    List<User> listAllUsers();

    /**
     * 插入数据并返回主键
     *
     * @param user
     * @return
     */
    @Insert("insert into  user (name, birthday)values (#{name},#{birthday})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", before = false, resultType = Long.class)
    int saveUser(User user);

    @Delete("delete from user where id = #{id} ")
    int removeUserById(Long id);

    @Update("update user set name = #{name} where id = #{id}")
    int updateUserById(@Param("name") String name, @Param("id") Long id);
}
